<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('ATT用户信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>名：</label>
                                <input type="text" name="firstName"/>
                            </li>
                            <li>
                                <label>姓：</label>
                                <input type="text" name="lastName"/>
                            </li>
                            <li>
                                <label>手机号：</label>
                                <input type="text" name="phone"/>
                            </li>
                            <li>
                                <label>是否使用：</label>
                                <select name="isUsed">
                                    <option value="">所有</option>
                                    <option value="0">未使用</option>
                                    <option value="1">已使用</option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="0">正常</option>
                                    <option value="1">停用</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="unlock:AttUserInfo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="unlock:AttUserInfo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="unlock:AttUserInfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="unlock:AttUserInfo:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" onclick="importUser()" shiro:hasPermission="unlock:AttUserInfo:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    
    <!-- 导入对话框 -->
    <div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="importModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="importModalLabel">批量导入用户</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <form id="importForm">
                        <div class="form-group">
                            <label for="userData">用户数据（每行一个用户，格式：名----姓----手机号）</label>
                            <textarea class="form-control" id="userData" name="userData" rows="10" placeholder="SIYA----VALDES----3057934720"></textarea>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="submitImport()">导入</button>
                </div>
            </div>
        </div>
    </div>
    
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('unlock:AttUserInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('unlock:AttUserInfo:remove')}]];
        var isUsedDatas = [[${@dict.getType('sys_yes_no')}]];
        var statusDatas = [[${@dict.getType('sys_normal_disable')}]];
        var prefix = ctx + "unlock/AttUserInfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "ATT用户信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'firstName',
                    title: '名'
                },
                {
                    field: 'lastName',
                    title: '姓'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },
                {
                    field: 'isUsed',
                    title: '是否使用',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isUsedDatas, value);
                    }
                },
                {
                    field: 'lastUsedTime',
                    title: '最后使用时间'
                },
                {
                    field: 'usedCount',
                    title: '使用次数'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        // 打开导入对话框
        function importUser() {
            $("#importModal").modal("show");
            $("#userData").val("");
        }
        
        // 提交导入数据
        function submitImport() {
            var userData = $("#userData").val();
            if (userData == "") {
                $.modal.alertWarning("请输入要导入的数据");
                return;
            }
            
            $.ajax({
                url: prefix + "/importData",
                type: "POST",
                data: {"userData": userData},
                success: function(result) {
                    if (result.code == 0) {
                        $.modal.closeAll();
                        $.modal.alertSuccess(result.msg);
                        $.table.refresh();
                    } else {
                        $.modal.alertError(result.msg);
                    }
                }
            });
        }
    </script>
</body>
</html> 